package com.justgame.project.module;

import com.justgame.project.generator.schema.Entity;
import com.justgame.project.generator.schema.Enumerate;
import com.justgame.project.generator.schema.IModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.justgame.project.generator.schema.Field.*;
import static com.justgame.project.generator.schema.Join.leftJoin;

@Configuration
public class ArtModule implements IModule {
    @Override
    public String getModule() {
        return "art";
    }

    @Bean
    public Entity ArtPageType(){
        return Entity.baseEntityBuilder(getModule(),"ArtPageType","文章类型表")
                .fields(
                        string("name","名称"),
                        string("otherName","别名"),
                        text("description","描述"),
                        url("imageUrl","图片"),
                        type("status","状态"),
                        string("remark","备注")
                )
                .enums(
                        Enumerate.builder("status")
                                .item("ENABLE","启用")
                                .item("DISABLE","禁用")
                )
                .build();
    }

    @Bean
    public Entity ArtPageComment(){
        return Entity.baseEntityBuilder(getModule(),"ArtPageComment","文章评论表")
                .fields(
                        key("parentId","父级评论"),
                        string("ancestors","族谱"),
                        key("pageId","文章信息"),
                        text("content","内容"),
                        type("type","类型"),
                        bool("isRemove","是否被显性删除"),
                        bool("isPixelate","是否匿名")
                )
                .enums(
                        Enumerate.builder("type")
                                .item("LANDLORD","楼主")
                                .item("FOLLOW","回复")
                )
                .joinTables(
                        leftJoin("parentComment","parentId","ArtPageComment","id"),
                        leftJoin("pageId","ArtPageInfo","id")
                )
                .build();
    }

    @Bean
    public Entity ArtPageGameMap(){
        return Entity.builder(getModule(),"ArtPageGameMap","文章关联游戏映射表")
                .fields(
                        key("pageId","文章信息"),
                        key("gameInfoId","游戏信息")
                )
                .joinTables(
                        leftJoin("pageId","ArtPageInfo","id"),
                        leftJoin("gameInfoId","JustGameInfo","id")
                )
                .build();
    }

    @Bean
    public Entity ArtPageInfo(){
        return Entity.baseEntityBuilder(getModule(),"ArtPageInfo","文章信息表")
                .fields(
                        url("imageUrl","封面图片"),
                        string("title","标题"),
                        text("content","文章内容"),
                        type("type","类型"),
                        bigint("watchCount","观看次数"),
                        bigint("shareCount","分享次数"),
                        bigint("likeCount","点赞次数"),
                        bool("isHidden","是否隐藏")
                )
                .enums(
                        Enumerate.builder("type")
                )
                .build();
    }

}
